home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / fontutil.6 / fontutil / fontutils-0.6 / imageto / bitmap2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-22  |  2.6 KB  |  84 lines

  1. /* bitmap2.c: extra bitmap manipulation routines.
  2.  
  3. Copyright (C) 1992 Free Software Foundation, Inc.
  4.  
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include "bitmap.h"
  22.  
  23. #include "bitmap2.h"
  24.  
  25.  
  26.  
  27. /* Put B2 to the right of B1, changing B1.  For example, if B1 looked
  28.    like `A' and B2 like `B', the result would look like `AB'.  The two
  29.    bitmaps must have the same number of rows.  */
  30.  
  31. void
  32. bitmap_concat (bitmap_type *b1, bitmap_type b2)
  33. {
  34.   bitmap_type new;
  35.   dimensions_type new_dimens;
  36.   unsigned row;
  37.   
  38.   assert (BITMAP_HEIGHT (*b1) == BITMAP_HEIGHT (b2));
  39.   
  40.   DIMENSIONS_WIDTH (new_dimens) = BITMAP_WIDTH (*b1) + BITMAP_WIDTH (b2);
  41.   DIMENSIONS_HEIGHT (new_dimens) = BITMAP_HEIGHT (b2);
  42.   new = new_bitmap (new_dimens);
  43.  
  44.   /* Choice of `b2' or `b1' here is arbitrary, of course.  */
  45.   for (row = 0; row < BITMAP_HEIGHT (b2); row++)
  46.     {
  47.       one_byte *target1 = BITMAP_ROW (new, row);
  48.       one_byte *target2 = target1 + BITMAP_WIDTH (*b1);
  49.       
  50.       memcpy (target1, BITMAP_ROW (*b1, row), BITMAP_WIDTH (*b1));
  51.       memcpy (target2, BITMAP_ROW (b2, row), BITMAP_WIDTH (b2));
  52.     }
  53.   
  54.   free_bitmap (b1);
  55.   *b1 = new;
  56. }
  57.  
  58.  
  59. /* Return a bitmap which consists of B1, one blank row, and B2.  The two
  60.    bitmaps must have the same width.  (The blank row is necessary
  61.    because one blank row is removed the first time we call
  62.    some_black_to_all_white; consider the row consisting of just an `!'.)*/
  63.  
  64. bitmap_type
  65. bitmap_vconcat (bitmap_type b1, bitmap_type b2)
  66. {
  67.   bitmap_type new;
  68.   dimensions_type new_dimens;
  69.   unsigned width = BITMAP_WIDTH (b1);
  70.   unsigned size1 = width * BITMAP_HEIGHT (b1);
  71.   unsigned size2 = width * BITMAP_HEIGHT (b2);
  72.   
  73.   assert (width == BITMAP_WIDTH (b2));
  74.   
  75.   DIMENSIONS_WIDTH (new_dimens) = width;
  76.   DIMENSIONS_HEIGHT (new_dimens) = BITMAP_HEIGHT (b1) + BITMAP_HEIGHT (b2) + 1;
  77.   new = new_bitmap (new_dimens);
  78.   
  79.   memcpy (BITMAP_BITS (new), BITMAP_BITS (b1), size1);
  80.   memcpy (BITMAP_BITS (new) + size1 + width, BITMAP_BITS (b2), size2);
  81.  
  82.   return new;
  83. }
  84.